package gamePack.entities;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import gamePack.Controller;
import gamePack.Game;
import gamePack.Physics;
import gamePack.gfx.Animation;
import gamePack.gfx.ImageManager;
import gamePack.gfx.SpriteSheet;

public class Player extends GameObject implements EntityA {

	private Game game;

	private final int SPEED = 3;

	private ImageManager im;
	private Animation upAnimation, downAnimation, upLeftAnimation,
			upRightAnimation, downLeftAnimation, downRightAnimation;

	private boolean up = false, dn = false, lt = false, rt = false;
	private boolean disparo = false, esta_disparando = false;

	private Physics fisica;
	private Controller c;

	public Player(int x, int y, Game game, ImageManager im, Controller c,
			Physics fisica) {
		super(x, y);
		this.game = game;
		this.im = im;
		this.c = c;
		this.fisica = fisica;
		upAnimation = new Animation(im.getPlayerUp(), 500);
		downAnimation = new Animation(im.getPlayerDown(), 500);
		upLeftAnimation = new Animation(im.getPlayerUpLeft(), 500);
		upRightAnimation = new Animation(im.getPlayerUpRight(), 500);
		downLeftAnimation = new Animation(im.getPlayerDownLeft(), 500);
		downRightAnimation = new Animation(im.getPlayerDownRight(), 500);
	}

	public void tick() {

		if (up) {
			if (y - SPEED > 0)
				y -= SPEED;
		}
		if (dn) {
			if (y + SPEED < game.getHeight() - 60)
				y += SPEED;
		}
		if (lt) {
			if (x - SPEED > -5)
				x -= SPEED;
		}
		if (rt) {
			if (x - SPEED < game.getWidth() - 40)
				x += SPEED;
		}
		if (disparo && !esta_disparando) {
			esta_disparando = true;
			c.addEntity(new Bullet(x, y - 10, game, im, c, fisica));
		}

	}

	public void render(Graphics g) {
		if (up && lt)
			upLeftAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else if (up && rt)
			upRightAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else if (up)
			upAnimation.render(g, x, y, game.getTileSize(), game.getTileSize());
		else if (dn && lt)
			downLeftAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else if (dn && rt)
			downRightAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else if (rt)
			downRightAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else if (lt)
			downLeftAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
		else
			downAnimation.render(g, x, y, game.getTileSize(),
					game.getTileSize());
	}

	public Rectangle getBounds() {
		return new Rectangle(x, y, 32, 32);
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setX(int valor) {
		x = valor;
	}

	public void setY(int valor) {
		y = valor;
	}

	public int getSpeed() {
		return SPEED;
	}

	public void setUp(boolean up) {
		this.up = up;
	}

	public void setDn(boolean dn) {
		this.dn = dn;
	}

	public void setLt(boolean lt) {
		this.lt = lt;
	}

	public void setRt(boolean rt) {
		this.rt = rt;
	}

	public void setDisparo(boolean disp) {
		this.disparo = disp;
	}

	public void setDisparando(boolean d) {
		this.esta_disparando = d;
	}

}
